﻿import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'feedback_history_logic.dart';

/// 反馈历史记录页面
class FeedbackHistoryView extends GetView<FeedbackHistoryLogic> {
  const FeedbackHistoryView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFF121212),
      appBar: AppBar(
        backgroundColor: const Color(0xFF121212),
        elevation: 0,
        leading: GestureDetector(
          onTap: () => Get.back(),
          child: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
            size: 20,
          ),
        ),
        title: const Text(
          '反馈历史',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w500,
          ),
        ),
        centerTitle: true,
      ),
      body: Obx(() {
        if (controller.isLoading.value) {
          return const Center(
            child: CircularProgressIndicator(
              valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFFF6B6B)),
            ),
          );
        }

        if (controller.feedbackList.isEmpty) {
          return Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Icon(
                  Icons.inbox_outlined,
                  size: 64.w,
                  color: const Color(0xFF666666),
                ),
                SizedBox(height: 16.h),
                Text(
                  '暂无反馈记录',
                  style: TextStyle(
                    color: const Color(0xFF666666),
                    fontSize: 14.sp,
                  ),
                ),
              ],
            ),
          );
        }

        return RefreshIndicator(
          onRefresh: controller.loadFeedbackList,
          color: const Color(0xFFFF6B6B),
          backgroundColor: const Color(0xFF2A2A2A),
          child: ListView.separated(
            padding: EdgeInsets.all(24.w),
            itemCount: controller.feedbackList.length,
            separatorBuilder: (context, index) => SizedBox(height: 12.h),
            itemBuilder: (context, index) {
              final feedback = controller.feedbackList[index];
              return _buildFeedbackItem(feedback);
            },
          ),
        );
      }),
    );
  }

  Widget _buildFeedbackItem(Map<String, dynamic> feedback) {
    return GestureDetector(
      onTap: () => controller.goToFeedbackDetail(feedback['id'].toString()),
      child: Container(
        padding: EdgeInsets.all(20.w),
        decoration: BoxDecoration(
          color: const Color(0xFF2A2A2A),
          borderRadius: BorderRadius.circular(16.r),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Text(
                    feedback['createTime'] ?? '',
                    style: TextStyle(
                      color: const Color(0xFF999999),
                      fontSize: 12.sp,
                    ),
                  ),
                ),                
              ],
            ),
            SizedBox(height: 12.h),
            Text(
              feedback['descProblem'] ?? '无描述',
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: Colors.white,
                fontSize: 14.sp,
              ),
            ),
            if (feedback['contactInfo'] != null) ...[
              SizedBox(height: 8.h),
              Text(
                '联系方式: ${feedback['contactInfo']}',
                style: TextStyle(
                  color: const Color(0xFF666666),
                  fontSize: 12.sp,
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }

  

  
}
